import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:my_flu01/page/pub/CommonBottomBar.dart';
/**
 * @author hanson
 * @version[创立日期，2023/9/11 16:15]
 * @function[功用简介 ]
 **/
class tableViewPage extends StatefulWidget {
  const tableViewPage({Key? key}) : super(key: key);

  @override
  _tableViewPageState createState() => _tableViewPageState();
}

class _tableViewPageState extends State<tableViewPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("tableView"),
        ),
        body: Center(
            child: Column(
              children: [
                Container(
                  child: Column(
                    children: _getDate(),
                  ),
                ),
                Expanded(
                  child: Table(
                      defaultColumnWidth: const FixedColumnWidth(100),
                      border: const TableBorder(
                        top: BorderSide(color: Colors.red),
                        left: BorderSide(color: Colors.red),
                        right: BorderSide(color: Colors.red),
                        bottom: BorderSide(color: Colors.red),
                        horizontalInside: BorderSide(color: Colors.red),
                        verticalInside: BorderSide(color: Colors.red),
                      ),
                      children: _tableRowList(),

                  ),
                )
              ],
            )
        ),
      bottomNavigationBar: CommonBottomBar(), // 使用公用的底部框
    );
  }

  List<TableRow> _tableRowList(){
    var count = listData.length;
    dynamic content;
    List<TableRow> tlist = <TableRow>[
      TableRow(
        children: [
          Center(child: Text("标题1"),),
          Center(child: Text("标题2"),),
          Center(child: Text("标题3"),),
        ]
      )
    ];
    for(var i =0;i<count;i++){
      content = TableRow(
        children: [
          Center(child: Text(listData[i]['title']),),
          Center(child: Text(listData[i]['author']),),
          Center(child: Text(listData[i]['author']),),
        ]
      );
      tlist.add(content);
    }
    return tlist;
  }

  /* @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("tableView"),
        ),
        body: Center(
          child: Column(
            children: [
              Table(
                defaultColumnWidth: const FixedColumnWidth(100),
                border: const TableBorder(
                  top: BorderSide(color: Colors.red),
                  left: BorderSide(color: Colors.red),
                  right: BorderSide(color: Colors.red),
                  bottom: BorderSide(color: Colors.red),
                  horizontalInside: BorderSide(color: Colors.red),
                  verticalInside: BorderSide(color: Colors.red),
                ),
                children: [
                  TableRow(
                      decoration: ShapeDecoration(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0)), color: Colors.blue),
                      children: const [
                        TableCell(child: Text('姓名',textAlign:TextAlign.center ,)),
                        TableCell(child: Text('性别',textAlign:TextAlign.center)),
                        TableCell(child: Text('年龄',textAlign:TextAlign.center)),
                      ]),
                  const TableRow(children: [
                    TableCell(child: Text('张三',textAlign:TextAlign.center)),
                    TableCell(child: Text('男',textAlign:TextAlign.center)),
                    TableCell(child: Text('20',textAlign:TextAlign.center)),
                  ]),
                  const TableRow(children: [
                    TableCell(child: Text('李四',textAlign:TextAlign.center)),
                    TableCell(child: Text('女',textAlign:TextAlign.center)),
                    TableCell(child: Text('18',textAlign:TextAlign.center)),
                  ]),
                ],
              )

            ],

          ),
        ) // This trailing comma makes auto-formatting nicer for build methods.
    );*/
  //}


//使用ListView.builder实现：
  List<Widget> _getDate() {
    var tempList = listData.map((e) {
      return ListTile(
        leading: Image.network((e)["imageUrl"]),
        title: Text(e["title"]),
        subtitle: Text(e["author"]),
        trailing: Icon(Icons.phone),
        onTap:(){

          GoRouter.of(context).pushNamed('card',  queryParameters: {'id':"3333"});
        },
      );
    }
      // (e) => ListTile(
      //   title: Text(e["title"]),
      // ),
    );
    return tempList.toList();
  }

}


List listData=[
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/1.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/2.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/3.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/4.png",
  },{
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/5.png",
  }
];